package com.hyz.assetManager.listener;

import clients.asset.asset.AssetClient;
import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.read.listener.ReadListener;
import com.hyz.assetManager.pojo.UploadAsset;
import com.hyz.pkg.util.GetValue;
import org.springframework.stereotype.Service;
import pojo.asset.asset.Asset;

import java.util.ArrayList;
import java.util.List;


/**
 * @author HGD
 * @date 2022/9/26 14:20
 */
@Service
public class UploadAssetListener implements ReadListener<UploadAsset> {

    private AssetClient assetClient;

    public UploadAssetListener(AssetClient assetClient) {
        this.assetClient = assetClient;
    }

    private final List<Asset> assetList = new ArrayList<>();


    @Override
    public void invoke(UploadAsset uploadAsset, AnalysisContext analysisContext) {
        assetList.add(uploadAsset.getAsset(uploadAsset));
    }


    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
        GetValue getValue = new GetValue();
        Long assetManagerId = getValue.getUuid();

        assetClient.batchInsertAsset(assetList);
    }

}
